/**
 * ABP vNext 前端类型定义
 * 为Matrix Framework项目定义ABP相关接口
 */

// ABP核心配置接口
export interface AbpCoreConfiguration {
  apis: {
    default: {
      url: string
    }
    [key: string]: {
      url: string
    }
  }
  localization: {
    currentCulture: {
      cultureName: string
      displayName?: string
    }
    languages: AbpLanguage[]
    resources: {
      [key: string]: AbpLocalizationResource
    }
  }
  auth: {
    grantedPolicies: {
      [key: string]: boolean
    }
  }
  features: {
    values: {
      [featureName: string]: any
    }
  }
  setting: {
    values: {
      [settingName: string]: string
    }
  }
  session: {
    tenant?: AbpTenantInfo
    user?: AbpUserInfo
  }
  timing: {
    timeZoneInfo: {
      windows: {
        timeZoneId: string
        currentUtcOffset: string
        isDaylightSavingTime: boolean
      }
      iana: {
        timeZoneId: string
      }
    }
  }
}

// ABP语言信息
export interface AbpLanguage {
  cultureName: string
  displayName: string
  icon?: string
  isDisabled: boolean
  isDefault: boolean
}

// ABP本地化资源
export interface AbpLocalizationResource {
  texts: {
    [key: string]: string
  }
  baseResources?: string[]
}

// ABP租户信息
export interface AbpTenantInfo {
  id?: string
  name?: string
  displayName?: string
  isDefault?: boolean
  editionId?: string
  editionDisplayName?: string
  connectionString?: string
}

// ABP用户信息
export interface AbpUserInfo {
  id: string
  userName: string
  name?: string
  surname?: string
  email?: string
  emailVerified?: boolean
  phoneNumber?: string
  phoneNumberVerified?: boolean
  isActive: boolean
  lockoutEnabled: boolean
  lockoutEnd?: Date
  twoFactorEnabled: boolean
  accessFailedCount: number
  concurrencyStamp?: string
  securityStamp?: string
  externalLogins?: any[]
  claims?: any[]
  roles?: string[]
  tenantId?: string
  tenant?: AbpTenantInfo
  issuer?: string
  subject?: string
  authenticationType?: string
  nameClaimType?: string
  roleClaimType?: string
}

// ABP权限信息
export interface AbpPermissionInfo {
  name: string
  displayName?: string
  description?: string
  parentName?: string
  isGranted: boolean
}

// ABP功能信息
export interface AbpFeatureInfo {
  name: string
  displayName?: string
  description?: string
  valueType: 'FreeText' | 'ToggleString' | 'Selection'
  value?: any
  defaultValue?: any
  allowedValues?: any[]
  isVisible: boolean
  isDisabled: boolean
}

// ABP设置信息
export interface AbpSettingInfo {
  name: string
  displayName?: string
  description?: string
  value?: string
  defaultValue?: string
  isVisible: boolean
  isDisabled: boolean
  group: string
}

// ABP API请求参数
export interface AbpRequestOptions {
  method?: string
  url?: string
  params?: any
  data?: any
  headers?: Record<string, string>
  timeout?: number
  skipErrorHandler?: boolean
  abp?: boolean
}

// ABP API响应
export interface AbpResponse<T = any> {
  result: T
  targetUrl?: string
  success: boolean
  error?: {
    code: number
    message: string
    details?: string
    validationErrors?: Array<{
      message: string
      members: string[]
    }>
  }
  unAuthorizedRequest: boolean
  __abp: boolean
}

// ABP分页请求
export interface AbpPagedRequest {
  sorting?: string
  skipCount?: number
  maxResultCount?: number
}

// ABP分页响应
export interface AbpPagedResult<T = any> {
  items: T[]
  totalCount: number
}

// ABP列表响应
export interface AbpListResult<T = any> {
  items: T[]
}

// ABP实体创建请求
export interface AbpCreateRequest<T = any> {
  item: T
}

// ABP实体更新请求
export interface AbpUpdateRequest<T = any> {
  id: string | number
  item: T
}

// ABP实体删除请求
export interface AbpDeleteRequest {
  id: string | number
}

// ABP批量请求
export interface AbpBulkRequest<T = any> {
  items: T[]
}

// ABP错误信息
export interface AbpError {
  code: number
  message: string
  details?: string
  validationErrors?: Array<{
    message: string
    members: string[]
  }>
}

// ABP日志级别
export type AbpLogLevel = 'Trace' | 'Debug' | 'Information' | 'Warning' | 'Error' | 'Critical' | 'None'

// ABP日志信息
export interface AbpLogInfo {
  level: AbpLogLevel
  message: string
  time?: Date
  exception?: any
  properties?: Record<string, any>
}

// ABP通知信息
export interface AbpNotificationInfo {
  id: string
  name: string
  creationTime: Date
  severity: 'Info' | 'Success' | 'Warn' | 'Error'
  type: string
  data?: any
  entityType?: string
  entityTypeName?: string
  entityId?: string
  userIds?: string[]
  tenantIds?: string[]
  isTransient: boolean
}

// ABP审计日志
export interface AbpAuditLogInfo {
  applicationName?: string
  userId?: string
  tenantId?: string
  executionTime: Date
  executionDuration: number
  clientIpAddress?: string
  clientName?: string
  browserInfo?: string
  extraProperties?: Record<string, any>
  exceptions?: any[]
  httpMethod?: string
  url?: string
  userName?: string
  tenantName?: string
  impersonatorUserId?: string
  impersonatorTenantId?: string
  impersonatorUserName?: string
  impersonatorTenantName?: string
  correlationId?: string
}

// ABP多租户解析结果
export interface AbpTenantResolveResult {
  tenantId?: string
  isDefault?: boolean
  isSubTenant?: boolean
  parentId?: string
}

// ABP用户登录请求
export interface AbpUserLoginRequest {
  username: string
  password: string
  rememberClient?: boolean
  tenant?: string
}

// ABP用户登录响应
export interface AbpUserLoginResponse {
  accessToken: string
  encryptedAccessToken: string
  expireInSeconds: number
  userId: string
  requireTwoFactorVerification: boolean
  twoFactorAuthProviders?: string[]
  twoFactorRememberClientToken?: string
  returnUrl?: string
  refreshToken?: string
  refreshTokenExpireInSeconds?: number
}

// ABP权限验证结果
export interface AbpPermissionValidationResult {
  result: boolean
  requiresPermissionCheck: boolean
  permissions: AbpPermissionInfo[]
}

// ABP功能检查结果
export interface AbpFeatureCheckResult {
  result: boolean
  featureValue?: any
}

// ABP设置获取结果
export interface AbpSettingGetResult {
  settingName: string
  value: string
  defaultValue: string
  group: string
}